package com.yuanqunsoft.alimigration.service.impl;

import com.yuanqunsoft.alimigration.dao.IApplicationDao;
import com.yuanqunsoft.alimigration.dao.IModuleDao;
import com.yuanqunsoft.alimigration.model.Application;
import com.yuanqunsoft.alimigration.model.Module;
import com.yuanqunsoft.alimigration.service.IFileUploadService;

public class FileUploadService implements IFileUploadService {

    private IApplicationDao applicationDao;
    private IModuleDao moduleDao;
    private String appName;
    private Application instance;

    @Override
    public boolean isFileUpload(Application application, Module module) {
        try {
            appName = application.getAppName();
            if (applicationDao.isNameExisted(appName)) {
                instance = (Application) applicationDao.findByName(appName).get(0);
                // 添加表中的module
                applicationDao.update(instance);
            }
            this.applicationDao.save(application);
            this.moduleDao.addModule(module);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }

    }

    public IApplicationDao getApplicationDao() {
        return applicationDao;
    }

    public void setApplicationDao(IApplicationDao applicationDao) {
        this.applicationDao = applicationDao;
    }

    public IModuleDao getModuleDao() {
        return moduleDao;
    }

    public void setModuleDao(IModuleDao moduleDao) {
        this.moduleDao = moduleDao;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public Application getInstance() {
        return instance;
    }

    public void setInstance(Application instance) {
        this.instance = instance;
    }

}
